home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap13 / Print2 / Print2.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  1.6 KB  |  63 lines

  1. /*-------------------------------------------
  2.    PRINT2.C -- Printing with Abort Procedure
  3.                (c) Charles Petzold, 1998
  4.   -------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. HDC  GetPrinterDC (void) ;              // in GETPRNDC.C
  9. void PageGDICalls (HDC, int, int) ;     // in PRINT.C
  10.  
  11. HINSTANCE hInst ;
  12. TCHAR     szAppName[] = TEXT ("Print2") ;
  13. TCHAR     szCaption[] = TEXT ("Print Program 2 (Abort Procedure)") ;
  14.  
  15. BOOL CALLBACK AbortProc (HDC hdcPrn, int iCode)
  16. {
  17.      MSG msg ;
  18.      
  19.      while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
  20.      {
  21.           TranslateMessage (&msg) ;
  22.           DispatchMessage (&msg) ;
  23.      }
  24.      return TRUE ;
  25. }
  26.  
  27. BOOL PrintMyPage (HWND hwnd)
  28. {
  29.      static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print2: Printing") } ;
  30.      BOOL           bSuccess = TRUE ;
  31.      HDC            hdcPrn ;
  32.      short          xPage, yPage ;
  33.      
  34.      if (NULL == (hdcPrn = GetPrinterDC ()))
  35.           return FALSE ;
  36.      
  37.      xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
  38.      yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
  39.      
  40.      EnableWindow (hwnd, FALSE) ;
  41.      
  42.      SetAbortProc (hdcPrn, AbortProc) ;
  43.      
  44.      if (StartDoc (hdcPrn, &di) > 0)
  45.      {
  46.           if (StartPage (hdcPrn) > 0)
  47.           {
  48.                PageGDICalls (hdcPrn, xPage, yPage) ;
  49.                
  50.                if (EndPage (hdcPrn) > 0)
  51.                     EndDoc (hdcPrn) ;
  52.                else
  53.                     bSuccess = FALSE ;
  54.           }
  55.      }
  56.      else
  57.           bSuccess = FALSE ;
  58.      
  59.      EnableWindow (hwnd, TRUE) ;
  60.      DeleteDC (hdcPrn) ;
  61.      return bSuccess ;
  62. }
  63.